package ui;

import services.UsersServicempl;
import vo.Users;

import java.util.List;
import java.util.Scanner;

public class UsersLogin {//客户
   static UsersServicempl usersServicempl =new UsersServicempl();//对客户表操作的具体类
    static Scanner scanner=new Scanner(System.in);
    public static void Login(){
        System.out.println("1,添加数据");
        System.out.println("2,删除数据");
        System.out.println("3,修改数据");
        System.out.println("4,查询数据");
        System.out.println("5,查询所有数据");
        System.out.println("0,返回上一级");
        System.out.println("请输入你的选择");
        int fuctionNumbre=scanner.nextInt();
        switch (fuctionNumbre){
            case 1:
                if(add()){
                    System.out.println("添加成功");
                }else {
                    System.out.println("添加失败");
                }
            case 2:
                if(delet()){
                    System.out.println("删除完成");
                }else {
                    System.out.println("删除失败");
                }
            case 3:
                if(modify()){
                    System.out.println("修改完成");
                }else {
                    System.out.println("修改失败");
                }
            case 4:
                Users users=getcustombyid();
                System.out.println(users);
                break;
            case 5:
                List<Users> list=getall();
                for(Users users1:list){
                    System.out.println(users1);
                }
                break;
            case 0:
                System.out.println("返回");
        }

    }

    private static boolean add() {
        System.out.println("请输入用户账号");
        String name=scanner.nextLine();
        System.out.println("请输入账号密码");
        String password=scanner.nextLine();
        Users users=new Users(name,password);
        return usersServicempl.add(users);
    }

    private static boolean delet() {
        System.out.println("请输入用户账号");
        String name=scanner.nextLine();
        System.out.println("请输入账号密码");
        String password=scanner.nextLine();
        Users users=new Users(name,password);
        return usersServicempl.delete(users);
    }

    private static boolean modify() {
        System.out.println("请输入用户账号");
        String name=scanner.nextLine();
        Users users=new Users(name);
        return usersServicempl.modify(users);
    }

    private static Users getcustombyid() {
        System.out.println("请输入用户账号");
        String name=scanner.nextLine();
        return usersServicempl.getcustombyid(name);
    }

    private static List<Users> getall() {
        return usersServicempl.getall();
    }
}
